#include "promptitem.h"
#include <QPainter>
#include "toolkit.h"
#include "resources.h"

PromptItem::PromptItem(int iComboNum):
    m_iComboNum(iComboNum),
    m_bFadeIn(true),
    m_bRun(true)
{
    setOpacity(0.0);
    m_timer.setInterval(100);
    connect(&m_timer,SIGNAL(timeout()),this,SLOT(ShowPrompt()));
}

void PromptItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    if(m_iComboNum == -1)
    {
        painter->drawPixmap(QRectF(13.0,0.0,91.0,36.0),
                            ToolKit::m_rc->m_PromatSuperImage,
                            QRectF(0.0,0.0,91.0,36.0));
    }
    else
    {
        painter->drawPixmap(QRectF(0.0,0.0,100.0,19.0),
                            ToolKit::m_rc->m_PromatComboImage,
                            QRectF(0.0,0.0,100.0,19.0));
        painter->drawPixmap(QRectF(101.0,0.0,17.0,19.0),
                            ToolKit::m_rc->m_PromatNumImage,
                            QRectF(m_iComboNum * 17.0,0.0,17.0,19.0));
    }
}

QRectF PromptItem::boundingRect() const
{
    return QRectF(0.0,0.0,117.0,36.0);
}

void PromptItem::ShowPrompt()
{
    if(m_bRun)
    {
        if(m_bFadeIn)
        {
            setOpacity(opacity() + 0.1);
            if(opacity() >= 1.0)
            {
                m_bFadeIn = false;
            }
        }
        else
        {
            setOpacity(opacity() - 0.1);
            if(opacity() <= 0.0)
            {
                m_bFadeIn = true;
                m_timer.stop();
                setVisible(false);
            }
        }
    }
}
